 package sprg;
 
 import java.io.UnsupportedEncodingException;
 import java.security.MessageDigest;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 public class encode
 {
   public static String addslashes(String paramString)
   {
     String str = paramString;
     str = str.replace("'", "''");
     str = str.replace("\\", "\\\\");
     return str;
   }
 	
			/**
			 * 将字节数组进行base64encode编码
			 * @param paramArrayOfByte 字节数组
			 * @return	编码字符串值
			 */
   public static String base64encode(byte[] paramArrayOfByte)
   {
     String str = "";
     byte[] arrayOfByte = paramArrayOfByte;
     char[] arrayOfChar = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' };
     StringBuffer localStringBuffer = new StringBuffer();
     int i = arrayOfByte.length;
     int j = 0;
 
     while (j < i)
     {
       int k = arrayOfByte[(j++)] & 0xFF;
       if (j == i)
       {
         localStringBuffer.append(arrayOfChar[(k >>> 2)]);
         localStringBuffer.append(arrayOfChar[((k & 0x3) << 4)]);
         localStringBuffer.append("==");
         break;
       }
       int l = arrayOfByte[(j++)] & 0xFF;
       if (j == i)
       {
         localStringBuffer.append(arrayOfChar[(k >>> 2)]);
         localStringBuffer.append(arrayOfChar[((k & 0x3) << 4 | (l & 0xF0) >>> 4)]);
         localStringBuffer.append(arrayOfChar[((l & 0xF) << 2)]);
         localStringBuffer.append("=");
         break;
       }
       int i1 = arrayOfByte[(j++)] & 0xFF;
       localStringBuffer.append(arrayOfChar[(k >>> 2)]);
       localStringBuffer.append(arrayOfChar[((k & 0x3) << 4 | (l & 0xF0) >>> 4)]);
       localStringBuffer.append(arrayOfChar[((l & 0xF) << 2 | (i1 & 0xC0) >>> 6)]);
       localStringBuffer.append(arrayOfChar[(i1 & 0x3F)]);
     }
     str = localStringBuffer.toString();
     return str;
   }
 	/**
			 * 将字符串进行base64decode反编译为字节数组
			 * @param paramString 字符串
			 * @return	字节数组
			 */
   public static byte[] base64decode(String paramString) throws UnsupportedEncodingException
   {
     byte[] arrayOfByte1 = null;
     String str = paramString;
     byte[] arrayOfByte2 = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1 };
     StringBuffer localStringBuffer = new StringBuffer();
     byte[] arrayOfByte3 = str.getBytes("US-ASCII");
     int i = arrayOfByte3.length;
     int j = 0;
 
     while (j < i) { int k;
       int l;
       int i1;
       int i2;
       do k = arrayOfByte2[arrayOfByte3[(j++)]];
       while ((j < i) && (k == -1));
       if (k == -1)
         break;
       do
         l = arrayOfByte2[arrayOfByte3[(j++)]];
       while ((j < i) && (l == -1));
       if (l == -1) break;
       localStringBuffer.append((char)(k << 2 | (l & 0x30) >>> 4));
       do
       {
         i1 = arrayOfByte3[(j++)];
         if (i1 == 61)
         {
           arrayOfByte1 = localStringBuffer.toString().getBytes("ISO-8859-1");
           return arrayOfByte1;
         }
         i1 = arrayOfByte2[i1]; }
       while ((j < i) && (i1 == -1));
       if (i1 == -1) break;
       localStringBuffer.append((char)((l & 0xF) << 4 | (i1 & 0x3C) >>> 2));
       do
       {
         i2 = arrayOfByte3[(j++)];
         if (i2 == 61)
         {
           arrayOfByte1 = localStringBuffer.toString().getBytes("ISO-8859-1");
           return arrayOfByte1;
         }
         i2 = arrayOfByte2[i2]; }
       while ((j < i) && (i2 == -1));
       if (i2 == -1) break;
       localStringBuffer.append((char)((i1 & 0x3) << 6 | i2));
     }
     arrayOfByte1 = localStringBuffer.toString().getBytes("ISO-8859-1");
     return arrayOfByte1;
   }
 	
			//将字符串中'/'转换为'_'
   public static String cachenameencode(String paramString)
   {
     String str = paramString;
     str = str.replace("/", "_");
     return str;
   }
 	
			//将字符串中'$CDATA#'转换为'<![CDATA[','#CDATA$'转换为']]>'
   public static String cdatadecode(String paramString)
   {
     String str = paramString;
     if (!(cls.isEmpty(str).booleanValue()))
     {
       str = str.replace("$CDATA#", "<![CDATA[");
       str = str.replace("#CDATA$", "]]>");
     }
     return str;
   }
 	
			//将字符串中'\n'转换为'\r\n'
   public static String encodeNewline(String paramString)
   {
     String str = paramString;
     str = str.replace(String.valueOf('\r') + String.valueOf('\n'), String.valueOf('\n'));
     str = str.replace(String.valueOf('\n'), String.valueOf('\r') + String.valueOf('\n'));
     return str;
   }
 	
			//将字符串中'\''转换为'&#39;','  '转换为'&nbsp;&nbsp;','\r\n''转换为'<br />'
   public static String encodeArticle(String paramString)
   {
     String str = paramString;
     str = encodeNewline(str);
     str = str.replace(String.valueOf('\''), "&#39;");
     str = str.replace(String.valueOf(' ') + String.valueOf(' '), "&nbsp;&nbsp;");
     str = str.replace(String.valueOf('\r') + String.valueOf('\n'), "<br />");
     return str;
   }

 	//将字符串每个字符都转成数字,如非数字则替换成0
   public static String encodeChar2String(String paramString)
   {
     String str1 = paramString;
     String str2 = "";
     if (!(cls.isEmpty(str1).booleanValue()))
     {
       String[] arrayOfString = str1.split(Pattern.quote(","));
       for (int i = 0; i < arrayOfString.length; ++i)
       {
         int j = cls.getNum(arrayOfString[i], Integer.valueOf(0)).intValue();
         str2 = str2 + String.valueOf((char)j);
       }
     }
     return str2;
   }
 	
			//将HTML代码转换：'&'转换为'&amp;','>'转换为'&gt;','<'转换为'&gt;','\"'转换为'&quot;'
   public static String encodeHtml(String paramString)
   {
     String str = paramString;
     str = str.replace("&", "&amp;");
     str = str.replace(">", "&gt;");
     str = str.replace("<", "&lt;");
     str = str.replace("\"", "&quot;");
     return str;
   }
 
			//将字符串'$'转换为'&#36;','@'转换为'&#64;'
   public static String encodeText(String paramString)
   {
     String str = paramString;
     str = str.replace("$", "&#36;");
     str = str.replace("@", "&#64;");
     return str;
   }
 	
			//将字符串同时对前2个方法进行转换（encodeHtml、encodeText）
   public static String htmlencode(String paramString)
   {
     String str1 = "";
     String str2 = paramString;
     str1 = htmlencode(str2, "0");
     return str1;
   }
 	
			//此方法功能同上，另加上一个第二个字符串的判断是否为1，如是则对第一字符串中'|'转换为'&#5;','='转换为'&#61;'
   public static String htmlencode(String paramString1, String paramString2)
   {
     String str1 = paramString2;
     String str2 = paramString1;
     str2 = cls.getString(str2);
     str2 = encodeHtml(str2);
     str2 = encodeText(str2);
     if (str1.equals("1"))
     {
       str2 = str2.replace("|", "&#5;");
       str2 = str2.replace("=", "&#61;");
     }
     return str2;
   }
 	
			//把字符串中","隔开的每个值两边再加上"|:|",最后还以字符串形式返回
   public static String keywordencode(String paramString)
   {
     String str1 = "";
     String str2 = paramString;
     if (!(cls.isEmpty(str2).booleanValue()))
     {
       String[] arrayOfString = str2.split(Pattern.quote(","));
       for (int i = 0; i < arrayOfString.length; ++i) str1 = str1 + "|:|" + arrayOfString[i] + "|:|,";
       if (!(cls.isEmpty(str1).booleanValue())) str1 = cls.getLRStr(str1, ",", "leftr");
     }
     return str1;
   }
 	
			//把字符串中"|:|"去除,最后还以字符串形式返回,与上述方法功能相反
   public static String keyworddecode(String paramString)
   {
     String str1 = "";
     String str2 = paramString;
     if (!(cls.isEmpty(str2).booleanValue()))
     {
       String[] arrayOfString = str2.split(Pattern.quote(","));
       for (int i = 0; i < arrayOfString.length; ++i) str1 = str1 + cls.getLRStr(cls.getLRStr(arrayOfString[i], "|:|", "leftr"), "|:|", "rightr") + ",";
       if (!(cls.isEmpty(str1).booleanValue())) str1 = cls.getLRStr(str1, ",", "leftr");
     }
     return str1;
   }
 
			//将字符串进行md5编码
   public static String md5(byte[] paramArrayOfByte)
   {
     String str = "";
     byte[] arrayOfByte1 = paramArrayOfByte;
     char[] arrayOfChar1 = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
     try
     {
       MessageDigest localMessageDigest = MessageDigest.getInstance("MD5");
       localMessageDigest.update(arrayOfByte1);
       byte[] arrayOfByte2 = localMessageDigest.digest();
       char[] arrayOfChar2 = new char[32];
       int i = 0;
       for (int j = 0; j < 16; ++j)
       {
         int k = arrayOfByte2[j];
         arrayOfChar2[(i++)] = arrayOfChar1[(k >>> 4 & 0xF)];
         arrayOfChar2[(i++)] = arrayOfChar1[(k & 0xF)];
       }
       str = new String(arrayOfChar2);
     } catch (Exception localException) {
     }
     return str;
   }
 
			//将字符串'\\'转换为'\\\\','‘'转换为'\\‘','\'转换为'\\\',并作encodeText方法转换
   public static String scriptencode(String paramString)
   {
     String str = paramString;
     str = str.replace("\\", "\\\\");
     str = str.replace("'", "\\'");
     str = str.replace("\"", "\\\"");
     str = encodeText(str);
     return str;
   }
 
   public static String unescape(String paramString)
   {
     String str1 = "";
     String str2 = paramString;
     if (!(cls.isEmpty(str2).booleanValue()))
     {
       byte[] arrayOfByte = { 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 63, 63, 63, 63, 63, 63, 63, 10, 11, 12, 13, 14, 15, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 10, 11, 12, 13, 14, 15, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63 };
       StringBuffer localStringBuffer = new StringBuffer();
       int i = 0;
       int j = str2.length();
       while (i < j)
       {
         int k = str2.charAt(i);
         if ((65 <= k) && (k <= 90))
         {
           localStringBuffer.append((char)k);
         }
         else if ((97 <= k) && (k <= 122))
         {
           localStringBuffer.append((char)k);
         }
         else if ((48 <= k) && (k <= 57))
         {
           localStringBuffer.append((char)k);
         }
         else if ((k == 45) || (k == 95) || (k == 46) || (k == 33) || (k == 126) || (k == 42) || (k == 39) || (k == 40) || (k == 41))
         {
           localStringBuffer.append((char)k);
         }
         else if (k == 37)
         {
           int l = 0;
           if ('u' != str2.charAt(i + 1))
           {
             l = l << 4 | arrayOfByte[str2.charAt(i + 1)];
             l = l << 4 | arrayOfByte[str2.charAt(i + 2)];
             i += 2;
           }
           else
           {
             l = l << 4 | arrayOfByte[str2.charAt(i + 2)];
             l = l << 4 | arrayOfByte[str2.charAt(i + 3)];
             l = l << 4 | arrayOfByte[str2.charAt(i + 4)];
             l = l << 4 | arrayOfByte[str2.charAt(i + 5)];
             i += 5;
           }
           localStringBuffer.append((char)l);
         }
         else
         {
           localStringBuffer.append((char)k);
         }
         ++i;
       }
       str1 = localStringBuffer.toString();
     }
     return str1;
   }
 
			//将字符串中的UBB代码转换成HTML代码
   public static String ubb2html(String paramString)
   {
     String str1 = paramString;
     if (!(cls.isEmpty(str1).booleanValue()))
     {
       Boolean localBoolean = Boolean.valueOf(true);
       str1 = htmlencode(str1);
       str1 = str1.replace(" ", "&nbsp;");
       str1 = str1.replace("&nbsp;&nbsp;", "[&nbsp-nbsp;]");
       str1 = str1.replace("&nbsp;", " ");
       str1 = str1.replace("[&nbsp-nbsp;]", "&nbsp; ");
       str1 = str1.replaceAll("\\[br\\]", "<br />");
       String[][] arrayOfString = { { "\\[p\\](.*?)\\[\\/p\\]", "$1<br />" }, { "\\[b\\](.*?)\\[\\/b\\]", "<b>$1</b>" }, { "\\[i\\](.*?)\\[\\/i\\]", "<i>$1</i>" }, { "\\[u\\](.*?)\\[\\/u\\]", "<u>$1</u>" }, { "\\[ol\\]([\\s\\S]*)\\[\\/ol\\]", "<ol>$1</ol>" }, { "\\[ul\\]([\\s\\S]*)\\[\\/ul\\]", "<ul>$1</ul>" }, { "\\[li\\](.*?)\\[\\/li\\]", "<li>$1</li>" }, { "\\[code\\]([\\s\\S]+?)\\[\\/code\\]", "<div class=\"ubb_code\">$1</div>" }, { "\\[quote\\]([\\s\\S]+?)\\[\\/quote\\]", "<div class=\"ubb_quote\">$1</div>" }, { "\\[color=([^\\]]*)\\](.*?)\\[\\/color\\]", "<font style=\"color: $1\">$2</font>" }, { "\\[hilitecolor=([^\\]]*)\\](.*?)\\[\\/hilitecolor\\]", "<font style=\"background-color: $1\">$2</font>" }, { "\\[align=([^\\]]*)\\](.*?)\\[\\/align\\]", "<div style=\"text-align: $1\">$2</div>" }, { "\\[url=([^\\]]*)\\](.*?)\\[\\/url\\]", "<a href=\"$1\" target=\"_blank\">$2</a>" }, { "\\[img\\]([^\\[]*?)\\[\\/img\\]", "<a href=\"$1\" target=\"_blank\"><img src=\"$1\" onload=\"cls.img.tResize(this, 600, 1800);\" /></a>" } };
 
       while (localBoolean.booleanValue())
       {
         localBoolean = Boolean.valueOf(false);
         for (int i = 0; i < arrayOfString.length; ++i)
         {
           Pattern localPattern = Pattern.compile(arrayOfString[i][0]);
           Matcher localMatcher = localPattern.matcher(str1);
           while (localMatcher.find())
           {
             localBoolean = Boolean.valueOf(true);
             String str2 = localMatcher.group();
             String str3 = arrayOfString[i][1];
             for (int j = 1; j < localMatcher.groupCount() + 1; ++j) str3 = str3.replace("$" + j, localMatcher.group(j));
             str1 = str1.replace(str2, str3);
           }
         }
       }
     }
     return str1;
   }
 }